package cn.controller;


import cn.pojo.User;
import cn.repository.UserRepository;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "helloFallBack1")
public class Hello {
    @Autowired
    private UserRepository userRepository;

//    @HystrixCommand(commandProperties = {
//            @HystrixProperty(name="circuitBreaker.requestVolumeThreshold",value = "4"),
//            @HystrixProperty(name="circuitBreaker.sleepWindowInMilliseconds",value = "20000"),
//            @HystrixProperty(name="circuitBreaker.errorThresholdPercentage",value = "60")
//    })
    @GetMapping("/hello/{id}")
    //@SentinelResource
    public User hello(@PathVariable("id") Integer id){
//        System.out.println("被调用了");
//        try {
//            Thread.sleep(1100);
//            System.out.println("查询成功");
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        //int a = 2 / 0;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
        User user = new User();
        user.setId(id);
        User user1 = userRepository.selectOne(user);
        User user2 = userRepository.selectUser(user);
        User user4 = userRepository.selectX();
        return user1;
    }
    public User helloFallBack(){
        return new User();
    }



}
